<?php

namespace Xin\VarDumper;

use Symfony\Component\VarDumper\Caster\ReflectionCaster;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;

class VarDumperException extends \RuntimeException
{
    /**
     * @var array
     */
    protected $vars = [];

    /**
     * @param array $vars
     */
    public function __construct(array $vars)
    {
        parent::__construct('VarDumperException');

        $this->vars = $vars;
    }

    /**
     * @return string
     */
    public function render(): string
    {
        $cloner = new VarCloner();
        $cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);
        $dumper = new HtmlDumper();

        ob_start();

        foreach ($this->vars as $v) {
            $dumper->dump($cloner->cloneVar($v));
        }

        return (string)ob_get_clean();
    }
}
